package com.epfuse.cloud.common.redis.serializer;


import com.epfuse.cloud.common.redis.serializer.impl.HessianSerializer;
import com.epfuse.cloud.common.redis.serializer.impl.Jackson2JsonSerializer;
import com.epfuse.cloud.common.redis.serializer.impl.JdkSerializer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @ClassName RedisSerializerAutoConfiguration
 * @Description **  @Import 一个普通类 spring会将该类加载到spring容器中 https://blog.csdn.net/weixin_45453628/article/details/124234317
 *
 * @Author 孙峰
 * @Date 2023/3/9 9:13
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({RedisSerializerProperties.class})
@Import({
        HessianSerializer.class,
        Jackson2JsonSerializer.class,
        JdkSerializer.class
})
public class RedisSerializerAutoConfiguration {

    /**
     * 序列化工厂
     *
     * @return OSS操作模板
     */
    @Bean
    @ConditionalOnMissingBean(DefaultSerializerProvider.class)
    @ConditionalOnProperty(prefix = RedisSerializerProperties.REDIS_PREFIX, name = "enable", havingValue = "true", matchIfMissing = true)
    public DefaultSerializerProvider defaultSerializerProvider(RedisSerializerProperties properties) {
        return new DefaultSerializerProvider(properties);
    }
}
